/**
 * Created by FDG348 on 2018/3/1.
 */
//滚动条在Y轴上的滚动距离
$('#reservationtime').daterangepicker({
    language:  'zh-CN',
    format: 'YYYY/MM/DD',
    locale: {
        format: 'YYYY-MM-DD',
        daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
        monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
    }
});

function getScrollTop(){
　　var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
　　if(document.body){
　　　　bodyScrollTop = document.body.scrollTop;
　　}
　　if(document.documentElement){
　　　　documentScrollTop = document.documentElement.scrollTop;
　　}
　　scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
　　return scrollTop;
}
 
//文档的总高度
function getScrollHeight(){
　　var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
　　if(document.body){
　　　　bodyScrollHeight = document.body.scrollHeight;
　　}
　　if(document.documentElement){
　　　　documentScrollHeight = document.documentElement.scrollHeight;
　　}
　　scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
　　return scrollHeight;
}

//浏览器视口的高度
function getWindowHeight(){
　　var windowHeight = 0;
　　if(document.compatMode == "CSS1Compat"){
　　　　windowHeight = document.documentElement.clientHeight;
　　}else{
　　　　windowHeight = document.body.clientHeight;
　　}
　　return windowHeight;
}
$(document).scroll(function(){
	var paging = $('#paging').val();
	if(getScrollTop() + getWindowHeight() == getScrollHeight()){
		var stop = $('#stop').val();
		if(stop != 1){
			paging++;
			searchLog(paging);
			$('#paging').val(paging);
		}
	}
})

function searchLog(paging){
	var id = $('#id').val();
	var reservationtime = $('#reservationtime').val();
	var content = $('#content').val();
	var oper = $('#oper').val();
	$.ajax({
        type: 'post',
        url: '/wish-single-report/search-log',
        data: {id:id,reservationtime:reservationtime,content:content,oper:oper,paging:paging},
        dataType: 'json',
        success: function (data) {
        	if(data.code == 200){
        		var result = data.val;
                // 选择需要显示的数据 拼接 DOM
                if(result.length > 0){
                	$('#stop').val(0);
                	$('.dropload-noData').addClass('hide');
                	var html = '';
                	result.forEach(function(e,index){
                		var log_type = parseInt(e.log_type);
                		var text = e.oper_time+'  由  '+e.oper+' '+e.content;
                        html += '<div><span class="text-primary">'+text+'</span>';
                        html += '</div><br/>';
                	});
                    setTimeout(function () {
                    	if(paging == 1){
                    		$('.goods_log_list ul').html(html);
                    	}else{
                    		$('.goods_log_list ul').append(html);
                    	}
                    }, 500);
                }else{
                	$('#stop').val(1);
                	$('.dropload-noData').removeClass('hide');
                	if(paging == 1){
                		$('.goods_log_list ul').html('');
                	}
                }
        	}else{
        		alert(data.val);
        	}
        }
    });
}
searchLog(1);

$('#reset_button').on('click',function(){
	var str_date = show();
	$('#reservationtime').val(str_date+' - '+str_date);
	$('#content').val('');
	$('#oper').val('');
	$('#paging').val(1);
	searchLog(1)
});

$('#select_button').on('click',function(){
	$('#paging').val(1);
	searchLog(1)
});

function show() {
    var date = new Date();
    var seperator1 = "-";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
    return currentdate;
}